package krow.dev.contest.view;

import java.util.ArrayList;
import java.util.List;

import krow.dev.contest.R;
import krow.dev.contest.model.ContestItem;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import android.widget.Toast;

public class ContestListAdapter extends BaseAdapter {

	private List<ContestItem> mDetailcategoryItemList;

	private LayoutInflater mLayoutInflater;
	
	public ContestListAdapter(Context context) {
	
		mDetailcategoryItemList = new ArrayList<ContestItem>();
		
		mLayoutInflater = LayoutInflater.from(context);
	}

	public void setDetailcategoryItemList(List<ContestItem> detailcategoryItemList){
		
		mDetailcategoryItemList.clear();
		mDetailcategoryItemList.addAll(detailcategoryItemList);
	}
	
	@Override
	public int getCount() {

		return mDetailcategoryItemList.size();
	}

	@Override
	public Object getItem(int position) {

		return mDetailcategoryItemList.get(position);
	}

	@Override
	public long getItemId(int position) {

		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
		final ContestItem detailcategoryItem = mDetailcategoryItemList.get(position);
		
		View view = mLayoutInflater.inflate(R.layout.item_contest, null);
		view.setTag(detailcategoryItem);
	
		TextView titleView = (TextView) view.findViewById(R.id.text_title);
		titleView.setText(detailcategoryItem.getTitle());
		
		TextView departmentView = (TextView) view.findViewById(R.id.text_department);
		departmentView.setText(detailcategoryItem.getDepartment());
		
		TextView creatorView = (TextView) view.findViewById(R.id.text_creator);
		creatorView.setText(detailcategoryItem.getCreator());
		
		
		return view;
	}	
	
}
